package com.brightworks.scripthelper.analyzers
{
    import com.brightworks.scripthelper.constants.LineTypeConstants;
    import com.brightworks.scripthelper.constants.PunctuationConstants;
    import com.brightworks.util.Utils_String;

    public class LineTypeAnalyzer_RoleIdentification extends LineTypeAnalyzer
    {
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
        //
        //          Getters & Setters
        //
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

        public static function get lineTypeDescription():String
        {
            return LineTypeConstants.LINE_TYPE_DESCRIPTION__ROLE_IDENTIFICATION;
        }

        public static function get lineTypeId():String
        {
            return LineTypeConstants.LINE_TYPE_ID__ROLE_IDENTIFICATION;
        }

        private var _rolesList:Array;
        public function set rolesList(value:Array):void
        {
            _rolesList = value;
        }

        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
        //
        //          Public Methods
        //
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

        public function LineTypeAnalyzer_RoleIdentification()
        {
            super();
        }

        override public function getProblemReports():Array
        {
            var problemList:Array = [];
            var lineString:String = Utils_String.removeWhiteSpaceIncludingLineReturnsFromEndOfString(lineText);
            if (Utils_String.doesStringBeginWithWhiteSpace(lineString))
            {
                problemList.push("This line appears to be a " + LineTypeConstants.LINE_TYPE_DESCRIPTION__ROLE_IDENTIFICATION + ". These lines should not start with white space (spaces, tabs, etc.), but this line does.");
            }
            else if (lineString.charAt(lineString.length - 1) == PunctuationConstants.COLON__CHINESE)
            {
                problemList.push("This line appears to be a " + LineTypeConstants.LINE_TYPE_DESCRIPTION__ROLE_IDENTIFICATION + ", but it uses a Chinese colon instead of an English colon. Please use an English colon here.");
            }
            else
            {
                // We know that the line doesn't start with white space, and ends with a colon
                var s:String = lineString.substring(0, lineString.length - 1);
                if (_rolesList.indexOf(s) != -1)
                {
                    roleName = s;
                }
                else
                {
                    problemList.push("This line appears to be a " + LineTypeConstants.LINE_TYPE_DESCRIPTION__ROLE_IDENTIFICATION + ", but the role that it names - '" + s + "' - isn't listed in the Roles line in the header." );
                }
            }
            return constructFullProblemStrings(problemList);
        }

        public static function isLineThisType(lineString:String, lineStringList:Array=null, lineNum:int=-1):Boolean
        {   
            // "Role" lines have blank lines before and after them and end with ":"
            // We're ignoring the "is this in the header" issue here - that would get caught elsewhere.
            if (lineNum < 2) 
                return false;
            if (!LineTypeAnalyzer_Blank.isLineThisType(lineStringList[lineNum - 2]))
                return false;
            if (!LineTypeAnalyzer_Blank.isLineThisType(lineStringList[lineNum]))
                return false;
            lineString = Utils_String.removeWhiteSpaceIncludingLineReturnsFromEndOfString(lineString);
            if (PunctuationConstants.COLONS.indexOf(lineString.charAt(lineString.length - 1)) == -1)
                return false;
            return true;
        }

        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
        //
        //          Private Methods
        //
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

    }
}

